package cn.tedu.apps_system.controller;

import cn.tedu.apps_system.base.response.JsonResult;
import cn.tedu.apps_system.base.response.ResultCode;
import cn.tedu.apps_system.pojo.dto.UserLoginDto;
import cn.tedu.apps_system.pojo.dto.UserRegDto;
import cn.tedu.apps_system.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@Api(tags = "01.用户管理模块")
@RestController
@RequestMapping("/api/v1/users/")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("注册功能")
    @ApiOperationSupport(order = 10)
    @PostMapping("public/reg")
    public JsonResult register(@RequestBody UserRegDto userRegDto) {
        return userService.registerUser(userRegDto);
    }

    @ApiOperation("登录功能")
    @ApiOperationSupport(order = 20)
    @PostMapping("public/login")
    public JsonResult login(@RequestBody UserLoginDto userLoginDto, @ApiIgnore HttpSession session) {
        return userService.loginUser(userLoginDto,session);
    }

    @ApiOperation("个人信息管理功能")
    @ApiOperationSupport(order = 30)
    @PostMapping("private/revise")
    public JsonResult revise(@RequestBody UserRegDto userRegDto, @ApiIgnore HttpSession session) {
        return userService.reviseUser(userRegDto,session);
    }

    @ApiOperation("退出登录功能")
    @ApiOperationSupport(order = 40)
    @PostMapping("public/logout")
    public JsonResult logout(@ApiIgnore HttpSession session) {
        return userService.logoutUser(session);
    }

}
